import { resolveComponent } from 'vue'
import { fliterDataWrapper } from 'common/js/table'

export const columns = (that) => {

  return [
    {
      key: 'area',
      align: 'center',
      width: 120,
      title: '学校属地',
      render: (h, params) => {
        const { row } = params

        return h('div', {}, [
          h('div', { }, '南海区委党校')
        ])

        // return fliterDataWrapper(h, row, 'name')
      }
    },
    {
      key: 'name',
      align: 'center',
      width: 120,
      title: '姓名',
      render: (h, params) => {
        const { row } = params
        const { name, mobilephone } = row

        return h('div', {}, [
          h('div', { }, name),
          h('div', { }, mobilephone)
        ])
      }
    },
    {
      key: 'department',
      title: '部门职务',
      align: 'center',
      width: 150,
      render: (h, params) => {
        const { row } = params

        return h('div', {}, [
          h('div', { }, '综合部'),
          h('div', { }, '部门领导')
        ])

        // return fliterDataWrapper(h, row, 'name')
      }
    },
    {
      key: 'roleid',
      title: '所属角色',
      render: (h, params) => {
        const { row } = params
        const { roleid } = row
        let str = '普通用户'

        if (roleid == 1) {
          str = '系统管理员'
        } else if (roleid == 2) {
          str = '教师'
        }

        return h('Tooltip', {
          props: {
            placement: 'top',
            content: '系统管理员、教师、等等'
          }
        }, [
          h('span', {}, str)
        ])
      }
    },
    {
      key: 'username',
      title: '用户名',
      render: (h, params) => {
        const { row } = params

        return fliterDataWrapper(h, row, 'username')
      }
    },
    {
      key: 'action',
      title: '操作',
      width: 185,
      render: (h, params) => {
        const { row } = params
        
        const list = [
          { text: '重置密码', type: 'primary', isPop: true, clickFn: () => { that.resetPsd(row) } },
          { text: '编辑', type: 'success', clickFn: () => { that.editClick(row) } },
          { text: '删除', type: 'error', isPop: true, clickFn: () => { that.deleteSinger(row) } }
        ]

        return h(resolveComponent('TableButton'), {
          list
        })
      }
    }
  ]
}
